Imports cmplib01


Public Class ctlBattleHandler
    Inherits System.Windows.Forms.UserControl

    Private ptrGameData As cmplib01.CampaignerGameData

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents pnlTextPanel As System.Windows.Forms.Panel
    Friend WithEvents lblText As System.Windows.Forms.Label
    Friend WithEvents tvwBattles As System.Windows.Forms.TreeView
    Friend WithEvents tvwInvolvedChits As System.Windows.Forms.TreeView
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.pnlTextPanel = New System.Windows.Forms.Panel()
        Me.lblText = New System.Windows.Forms.Label()
        Me.tvwBattles = New System.Windows.Forms.TreeView()
        Me.tvwInvolvedChits = New System.Windows.Forms.TreeView()
        Me.pnlTextPanel.SuspendLayout()
        Me.SuspendLayout()
        '
        'pnlTextPanel
        '
        Me.pnlTextPanel.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.pnlTextPanel.BackColor = System.Drawing.Color.SteelBlue
        Me.pnlTextPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlTextPanel.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblText})
        Me.pnlTextPanel.Name = "pnlTextPanel"
        Me.pnlTextPanel.Size = New System.Drawing.Size(448, 32)
        Me.pnlTextPanel.TabIndex = 1
        '
        'lblText
        '
        Me.lblText.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblText.Location = New System.Drawing.Point(8, 5)
        Me.lblText.Name = "lblText"
        Me.lblText.Size = New System.Drawing.Size(152, 24)
        Me.lblText.TabIndex = 0
        Me.lblText.Text = "Battles"
        '
        'tvwBattles
        '
        Me.tvwBattles.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.tvwBattles.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tvwBattles.ImageIndex = -1
        Me.tvwBattles.Location = New System.Drawing.Point(8, 40)
        Me.tvwBattles.Name = "tvwBattles"
        Me.tvwBattles.SelectedImageIndex = -1
        Me.tvwBattles.ShowRootLines = False
        Me.tvwBattles.Size = New System.Drawing.Size(216, 64)
        Me.tvwBattles.TabIndex = 2
        '
        'tvwInvolvedChits
        '
        Me.tvwInvolvedChits.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.tvwInvolvedChits.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tvwInvolvedChits.ImageIndex = -1
        Me.tvwInvolvedChits.Location = New System.Drawing.Point(232, 40)
        Me.tvwInvolvedChits.Name = "tvwInvolvedChits"
        Me.tvwInvolvedChits.SelectedImageIndex = -1
        Me.tvwInvolvedChits.ShowRootLines = False
        Me.tvwInvolvedChits.Size = New System.Drawing.Size(208, 64)
        Me.tvwInvolvedChits.TabIndex = 3
        '
        'ctlBattleHandler
        '
        Me.BackColor = System.Drawing.Color.LightSkyBlue
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.tvwInvolvedChits, Me.tvwBattles, Me.pnlTextPanel})
        Me.Name = "ctlBattleHandler"
        Me.Size = New System.Drawing.Size(448, 112)
        Me.pnlTextPanel.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Sub ShowBattles(ByVal Gamedata As cmplib01.CampaignerGameData)
        Dim batt As cmplib01.Battle
        Dim key As String

        ' first we always clear the battles
        ClearBattles()

        ptrGameData = Gamedata

        For Each key In ptrGameData.Battles_g.HT.Keys
            Dim nod As New TreeNode()
            batt = ptrGameData.Battles_g.Item(key)
            nod.Text = batt.BattleName & ": " & batt.BattleResultString()
            nod.Tag = batt.Key
            tvwBattles.Nodes.Add(nod)
        Next

    End Sub

    Public Sub ClearBattles()
        tvwBattles.Nodes.Clear()
    End Sub

    Private Sub tvwBattles_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwBattles.AfterSelect
        Try
            '            Dim unit As cmplib01.UnitType
            Dim batt As cmplib01.Battle
            batt = ptrGameData.Battles_g.Item(e.Node.Tag)

            tvwInvolvedChits.Nodes.Clear()

            For Each mem As ChitMember In batt.InvolvedChits
                Dim nod As New TreeNode()
                nod.Text = mem.Name
                tvwInvolvedChits.Nodes.Add(nod)
            Next

        Catch ex As Exception
            HandleException("ctlBattlesLister.tvwBattles.AfterSelect", ex)
        End Try
    End Sub

End Class
